//
// Created by wangwanlong on 2024/11/1.
//

#ifndef MKAHYPAR_RATING_ACCEPTANCE_POLICY_H
#define MKAHYPAR_RATING_ACCEPTANCE_POLICY_H
#include "mkahypar/utils/typedef.h"
#include "mkahypar/datastructure/fast_reset_flag_array.h"
#include "mkahypar/partition/coarsening/policies/rating_tie_breaking_policy.h"
#include "mkahypar/utils/policy_registry.h"
namespace mkahypar{
  template <class TieBreakingPolicy = RandomRatingWins>
  class BestRatingWithTieBreaking final : public meta::PolicyBase {
  public:
    MKAHYPAR_ATTRIBUTE_ALWAYS_INLINE static inline bool acceptRating(const RatingType tmp,
                                                                    const RatingType max_rating,
                                                                    const HypernodeID,
                                                                    const HypernodeID,
                                                                    const ds::FastResetFlagArray<>&) {
      return max_rating < tmp || (max_rating == tmp && TieBreakingPolicy::acceptEqual());
    }
  };


  template <class TieBreakingPolicy = RandomRatingWins>
  class BestRatingPreferringUnmatched final : public meta::PolicyBase {
  public:
    MKAHYPAR_ATTRIBUTE_ALWAYS_INLINE static inline bool acceptRating(const RatingType tmp,
                                                                    const RatingType max_rating,
                                                                    const HypernodeID old_target,
                                                                    const HypernodeID new_target,
                                                                    const ds::FastResetFlagArray<>& already_matched) {
      return max_rating < tmp ||
             ((max_rating == tmp) &&
              ((already_matched[old_target] && !already_matched[new_target]) ||
               (already_matched[old_target] && already_matched[new_target] &&
                TieBreakingPolicy::acceptEqual()) ||
               (!already_matched[old_target] && !already_matched[new_target] &&
                TieBreakingPolicy::acceptEqual())));
    }
  };
}
#endif //MKAHYPAR_RATING_ACCEPTANCE_POLICY_H
